package com.hanbang.chu_xing_gao_zhao.base;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hanbang.chu_xing_gao_zhao.application.ActivityManager;
import com.hanbang.chu_xing_gao_zhao.utils.MyToast;
import com.hanbang.chu_xing_gao_zhao.utils.UiUtils;
import com.hanbang.chu_xing_gao_zhao.view_dynamic.DynamicActivity;
import com.hanbang.chu_xing_gao_zhao.view_find.FindMainFragmentActivity;
import com.hanbang.chu_xing_gao_zhao.view_information.InformationActivity;
import com.hanbang.chu_xing_gao_zhao.view_me.MeActivity;
import com.hanbang.cxgz_2.R;

public class MainActivity extends BaseDataActivity implements android.view.View.OnClickListener {

	private long exitTime = 0;
	public LinearLayout dynamic;
	public LinearLayout find;
	public LinearLayout information;
	public LinearLayout me;
	public LinearLayout current;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}


	/**
	 * 获取控件,添加监听,更改底控件的颜色
	 */
	public void setUpViewsAndAddLinstener(LinearLayout layout) {
		this.current = layout;

		dynamic = (LinearLayout) findViewById(R.id.bar_botton_bar_dynamic);
		find = (LinearLayout) findViewById(R.id.bar_botton_bar_find);
		information = (LinearLayout) findViewById(R.id.bar_botton_bar_information);
		me = (LinearLayout) findViewById(R.id.bar_botton_bar_me);

		dynamic.setOnClickListener(this);
		find.setOnClickListener(this);
		information.setOnClickListener(this);
		me.setOnClickListener(this);
		current.setBackgroundResource(R.drawable.bg_corners0_white_backgound);

	}

	/**
	 * 处理监听
	 */

	@Override
	public void onClick(View v) {

		if (!isLogin(true)) {
			return;
		}
		Intent intent = new Intent();

		if (current.getId() == v.getId()) {
			return;
		}

		switch (v.getId()) {

		case R.id.bar_botton_bar_dynamic:
			intent.setClass(MainActivity.this, DynamicActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(intent);
			break;
		case R.id.bar_botton_bar_find:
			intent.setClass(MainActivity.this, FindMainFragmentActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(intent);

			break;
		case R.id.bar_botton_bar_information:
			intent.setClass(MainActivity.this, InformationActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(intent);

			break;
		case R.id.bar_botton_bar_me:
			intent.setClass(MainActivity.this, MeActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(intent);

			break;


		default:
			break;
		}

	}

	/**
	 * 设置当前LinearLayout 的颜色
	 */
	@Override
	protected void onResume() {
		super.onResume();

	}

	/**
	 * 设置非当前LinearLayout 的颜色
	 */
	@Override
	protected void onPause() {
		super.onPause();
//		current.setBackgroundColor(0x00000000);
	}

	public void setBottonButton(ViewGroup current) {
		UiUtils.setButton(current, true);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		isExitApplication(this);
	}

	/**
	 * 退出程序
	 *
	 * @param context
	 */
	public void isExitApplication(Context context) {
		if ((System.currentTimeMillis() - exitTime) > 2000) {
			MyToast.show(this, "再按一次退出程序", Toast.LENGTH_SHORT);
			exitTime = System.currentTimeMillis();
		} else {
			// 退出
			ActivityManager.getInstance().exitAllActivity();
		}
	}



}
